package net.neuronal.tasador;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Map;

public class NormalizarCaballito {
	
	public static void main(String[] args) {
		
		File input = new File("caballito.txt");
		File output = new File("output.txt");
		
		//calle, numero, m2 -> dolares
		
		Map<String,String> calles = Util.readFile("calle.txt", 49);
		Map<String,String> numeros = Util.readFile("numeros.txt", 100, 5288);
		Map<String,String> m2 = Util.readFile("m2.txt", 85, 3280);
		Map<String,String> dolares = Util.readFile("dolar.txt", 46500, 2700000);
		
		BufferedReader br = null;
		BufferedWriter bw = null;
		
		try {
			
			br = new BufferedReader(new FileReader(input));
			bw = new BufferedWriter(new FileWriter(output));
			
			String readLine;
			StringBuffer writeLine = new StringBuffer();
			
			while ((readLine = br.readLine()) != null) {
				
				String[] split = readLine.split(";");
				
				writeLine.delete(0, writeLine.length());
				
				writeLine.append(calles.get(split[0]) + ";");
				writeLine.append(numeros.get(split[1]) + ";");
				writeLine.append(m2.get(split[2]) + ";");
				writeLine.append(dolares.get(split[3]));
				
				bw.write(writeLine.toString());
				bw.newLine();
			}
		}
		catch(Exception e){
			e.printStackTrace();
		}
		finally{
			try {
				br.close();
				bw.flush();
				bw.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}		
	}
}
